import { createRouter, createWebHistory } from 'vue-router'
import transitionExtend from './transition-extend'
import generatedRoutes from '@/generatedRoutes'
import store from '../store'
import { HandDrawnNotification } from '@/tool/handDrawnToast'

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes: generatedRoutes
})

const extendedRouter = transitionExtend(router)

router.beforeEach((to, from, next) => {
  if (!store.getters.isAuthenticated && to.path !== "/") {
    HandDrawnNotification.info({
      title: "未登录",
      message: `请先登陆.`,
    });
    next("/");
  } else {
    next();
  }
})

export default extendedRouter
